package android.framework.paging;

import android.content.Context;
import android.framework.reflaction.injectors.IReflactionInjector;
import android.view.LayoutInflater;
import android.view.View;

public abstract class BaseViewInitializer implements IViewInitalizer {

	private LayoutInflater inflater;
	private int layout;
	private View view;
	protected Context context;
	private IInitListener initListener;
	
	public BaseViewInitializer(IInitListener initListener, Context context, int layout){
		this.initListener = initListener;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.layout = layout;
		this.context = context;
	}
	
	public View initView() {
		this.view = inflater.inflate(layout, null);
		inject(view);
		init(view);
		if(initListener != null){
			initListener.init();
		}
        return view;
	}
	
	

	private void inject(final View view) {
		for (IReflactionInjector injector : ReflactionInjectorsFactory.injectors) {
			injector.Inject(view, this);
		}
	}
	
	protected View getView(){
		return this.view;
	}

	
	public abstract void init(View view);

	public IInitListener getInitListener() {
		return initListener;
	}

	public void setInitListener(IInitListener initListener) {
		this.initListener = initListener;
	}
	

}
